﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace PoolGame2.Game
{
    class GameScreenMessage
    {
        Texture2D overlayMessage;
        Vector2 messagePos;
        float messageCreated;       //time the message was created
        float messageDisplay;       //how long the message is displayed for
        SpriteBatch spriteBatch;    //reference to the GameScreenOverlays's spritebatch

        public GameScreenMessage(float timeC, float length,Vector2 pos, Texture2D msg,SpriteBatch sprite)
        {
            messagePos = pos;
            overlayMessage = msg;
            messageCreated = timeC;
            messageDisplay = length;
            spriteBatch = sprite;
        }

        public void Draw(GameTime gametime)
        {
            float fade = 1;
            if ((gametime.TotalGameTime.TotalMilliseconds > messageCreated + (messageDisplay / 2)))
            {
                fade = 1 - ((float)gametime.TotalGameTime.TotalMilliseconds - (messageCreated + (messageDisplay / 2))) / (messageDisplay / 2);
            }

            spriteBatch.Draw(overlayMessage, messagePos, null, new Color(1.0f, 1.0f, 1.0f, fade));

        }

        //should the message still be displayed
        public bool StillDisplayed(GameTime gametime)
        {
            if (gametime.TotalGameTime.TotalMilliseconds > messageCreated + messageDisplay)
            {
                return false;
            }
           
            return true;
        }

    }


}
